(global.webpackJsonp = global.webpackJsonp || []).push([ [ "pages/public/kefu/index" ], {
    "0454": function(e, t, s) {
        s.r(t);
        var o, a = s("3666"), n = s.n(a);
        for (o in a) "default" !== o && function(e) {
            s.d(t, e, function() {
                return a[e];
            });
        }(o);
        t.default = n.a;
    },
    3666: function(e, a, n) {
        (function(r) {
            Object.defineProperty(a, "__esModule", {
                value: !0
            }), a.default = void 0;
            var e, i = (e = n("2313")) && e.__esModule ? e : {
                default: e
            }, t = n("26cb");
            function s(t, e) {
                var s, o = Object.keys(t);
                return Object.getOwnPropertySymbols && (s = Object.getOwnPropertySymbols(t), e && (s = s.filter(function(e) {
                    return Object.getOwnPropertyDescriptor(t, e).enumerable;
                })), o.push.apply(o, s)), o;
            }
            r.getStorageSync("token");
            var o = "", c = null, t = {
                components: {},
                data: function() {
                    return {
                        leaveMessage: {
                            name: "",
                            contact: "",
                            message: ""
                        },
                        attachBackground: "",
                        showSendButton: !1,
                        showTool: !1,
                        showLeaveMessage: !1,
                        expressionData: [],
                        scrollIntoFooter: "",
                        config: [],
                        tokenList: [],
                        kefuMessage: "",
                        wrapperHeight: 46,
                        ws: {
                            SocketTask: null,
                            Timer: null,
                            ErrorMsg: [],
                            MaxRetryCount: 3,
                            CurrentRetryCount: 0,
                            socketOpen: !1,
                            pageHideCloseWs: !0,
                            unloadCloseWs: !1
                        },
                        csr: "",
                        sessionId: 0,
                        sessionUser: "",
                        kefuMessageFocus: !1,
                        messageList: [],
                        chatRecordPage: 1,
                        errorTips: "链接中...",
                        selectModel: !1,
                        selectModelType: {
                            goods: "发送商品",
                            order: "发送订单"
                        },
                        selectModelData: [],
                        writeBottom: 0
                    };
                },
                computed: function(o) {
                    for (var e = 1; e < arguments.length; e++) {
                        var a = null != arguments[e] ? arguments[e] : {};
                        e % 2 ? s(Object(a), !0).forEach(function(e) {
                            var t, s;
                            t = o, e = a[s = e], s in t ? Object.defineProperty(t, s, {
                                value: e,
                                enumerable: !0,
                                configurable: !0,
                                writable: !0
                            }) : t[s] = e;
                        }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(o, Object.getOwnPropertyDescriptors(a)) : s(Object(a)).forEach(function(e) {
                            Object.defineProperty(o, e, Object.getOwnPropertyDescriptor(a, e));
                        });
                    }
                    return o;
                }({}, (0, t.mapState)({
                    userInfo: function(e) {
                        return e.user.userInfo;
                    }
                })),
                onLoad: function(e) {
                    o = e.fixed_csr || o;
                },
                onShow: function() {
                    this.ws.pageHideCloseWs || (this.ws.pageHideCloseWs = !0), this.load();
                },
                onHide: function() {
                    this.ws.SocketTask && this.ws.socketOpen && this.ws.pageHideCloseWs && (console.log("微信小程序页面hide主动关闭链接"), 
                    r.closeSocket());
                },
                onUnload: function() {
                    this.ws.SocketTask && this.ws.socketOpen && (console.log("页面卸载主动关闭链接"), this.ws.unloadCloseWs = !0, 
                    r.closeSocket());
                },
                methods: {
                    load: function() {
                        var n = this, e = "";
                        try {
                            e = (e = r.getStorageSync("kefu_tourists_token")) || "";
                        } catch (e) {
                            console.error(e);
                        }
                        r.request({
                            url: n.build_url("initialize"),
                            data: {
                                token: r.getStorageSync("token"),
                                kefu_tourists_token: e,
                                fixed_csr: o
                            },
                            success: function(e) {
                                if (1 == e.data.code) {
                                    if (e.data.data.token_list.kefu_tourists_token) try {
                                        r.setStorageSync("kefu_tourists_token", e.data.data.token_list.kefu_tourists_token);
                                    } catch (e) {
                                        console.error(e);
                                    }
                                    (c = r.createInnerAudioContext()).src = n.build_url("message_prompt");
                                    var t = "";
                                    try {
                                        t = r.getStorageSync("kefu_notice");
                                    } catch (e) {
                                        console.log(e);
                                    }
                                    t == e.data.data.config.announcement && (e.data.data.config.announcement = ""), 
                                    n.config = e.data.data.config, n.tokenList = e.data.data.token_list, e.data.data.new_msg && n.new_message_prompt();
                                    var s, o = i.default.https_switch ? "https://" : "http://", a = {};
                                    for (s in i.default.expression) a[s] = {
                                        src: o + i.default.baseURL + "/assets/addons/kefu/img" + i.default.expression[s].src,
                                        title: i.default.expression[s].title
                                    };
                                    n.expressionData = a, n.attachBackground = n.build_url("res", "/img/more.png"), 
                                    n.connect_socket();
                                } else r.showModal({
                                    content: e.data.msg,
                                    showCancel: !1,
                                    success: function(e) {
                                        e.confirm && r.navigateBack({
                                            delta: 1
                                        });
                                    }
                                });
                            },
                            fail: function(e) {
                                r.showModal({
                                    title: "温馨提示",
                                    content: "在线客服初始化失败,请重试~",
                                    showCancel: !1
                                }), n.errorTips = "初始化失败";
                            }
                        });
                    },
                    switch_show_tool: function(e) {
                        e ? (this.showTool = e, this.writeBottom = 170, this.scroll_into_footer(200)) : (this.showTool = !1, 
                        this.writeBottom = 0);
                    },
                    close_notice: function() {
                        r.setStorageSync("kefu_notice", this.config.announcement), this.config.announcement = "";
                    },
                    select_done: function(e) {
                        var t, s = e.detail.value, o = "";
                        for (t in this.selectModelData[s]) o += t + "=" + this.selectModelData[s][t] + "#";
                        this.send_message(o, "goods" == this.selectModel ? 4 : 5), this.selectModel = !1, 
                        this.switch_show_tool(!1);
                    },
                    show_select_model: function(e) {
                        var t, s = this;
                        (this.selectModel = e) && (r.showLoading({
                            title: "请稍后..."
                        }), t = this.config.toolbar[e].data_api, e = new RegExp("(^https?://)", "i"), -1 === t.search(e) && (t = (i.default.https_switch ? "https://" : "http://") + i.default.baseURL + t), 
                        this.selectModelData = [], r.request({
                            url: t,
                            data: {
                                token: r.getStorageSync("token")
                            },
                            success: function(e) {
                                1 == e.data.code ? (console.log(e.data.data), s.selectModelData = e.data.data.data) : r.showModal({
                                    title: "温馨提示",
                                    content: e.data.msg,
                                    showCancel: !1
                                });
                            },
                            fail: function(e) {
                                r.showModal({
                                    title: "温馨提示",
                                    content: "网络请求失败，请重试！",
                                    showCancel: !1
                                });
                            },
                            complete: function(e) {
                                r.hideLoading();
                            }
                        }));
                    },
                    parseUrl: function(e) {
                        var t = new RegExp("(https?://)([0-9a-z.]+)([?0-9a-z&=]+)?(#[0-9-a-z]+)?", "g");
                        return e.replace(t, '<a target="_blank" title="$&" class="link" href="$&">$&</a>');
                    },
                    message_img_preview: function(e) {
                        this.ws.pageHideCloseWs = !1;
                    },
                    preview_img: function(e) {
                        this.ws.pageHideCloseWs = !1, r.previewImage({
                            current: e,
                            urls: [ e ]
                        });
                    },
                    upload_file: function() {
                        var t = this;
                        t.ws.pageHideCloseWs = !1, r.chooseImage({
                            success: function(e) {
                                e = e.tempFilePaths;
                                r.showLoading({
                                    title: "正在上传..."
                                }), r.uploadFile({
                                    url: t.build_url("upload"),
                                    filePath: e[0],
                                    name: "file",
                                    formData: {
                                        token: r.getStorageSync("token")
                                    },
                                    success: function(e) {
                                        r.hideLoading(), t.ws.pageHideCloseWs = !0, 1 == (e = JSON.parse(e.data)).code ? (t.send_message(e.data.url, 1), 
                                        t.switch_show_tool(!1), t.kefuMessageFocus = !0) : r.showModal({
                                            title: "温馨提示",
                                            content: e.msg,
                                            showCancel: !1
                                        });
                                    },
                                    complete: function(e) {
                                        r.hideLoading();
                                    }
                                }).onProgressUpdate(function(e) {
                                    r.showLoading({
                                        title: e.progress + "%"
                                    });
                                });
                            }
                        });
                    },
                    connect_socket: function() {
                        var s = this;
                        this.ws.SocketTask && this.ws.socketOpen ? console.log("无需链接") : (s.ws.SocketTask = r.connectSocket({
                            url: this.build_url("ws"),
                            header: {
                                "content-type": "application/json"
                            },
                            complete: function(e) {}
                        }), r.onSocketOpen(function(e) {
                            for (var t in console.log("链接已打开"), s.ws.socketOpen = !0, s.ws.CurrentRetryCount = 0, 
                            s.ws.ErrorMsg) s.ws_send(s.ws.ErrorMsg[t]);
                            s.ws.ErrorMsg = [], s.errorTips = "", null != s.ws.Timer && clearInterval(s.ws.Timer), 
                            s.ws.Timer = setInterval(s.ws_send, 28e3);
                        }), r.onSocketMessage(function(e) {
                            e = JSON.parse(e.data);
                            s.domsg(e);
                        }), r.onSocketError(function(e) {
                            s.ws.socketOpen = !1, s.errorTips = "WebSocket 发生错误!", console.log("链接出错", e);
                        }), r.onSocketClose(function(e) {
                            console.log("链接已关闭", e), s.ws.socketOpen = !1, 1e3 == e.code || 1e4 == e.code || s.ws.unloadCloseWs || (null != s.ws.Timer && clearInterval(s.ws.Timer), 
                            s.ws.socketOpen = !1, -1 === s.errorTips.indexOf("重连") && (s.errorTips = "网络链接已断开!"), 
                            s.ws.MaxRetryCount && (s.ws.Timer = setInterval(s.retry_websocket, 3e3)));
                        }));
                    },
                    retry_websocket: function() {
                        var e = this;
                        e.ws.CurrentRetryCount < e.ws.MaxRetryCount ? (e.ws.CurrentRetryCount++, e.connect_socket(), 
                        e.errorTips = "重连WebSocket第" + e.ws.CurrentRetryCount + "次") : (null != e.ws.Timer && clearInterval(e.ws.Timer), 
                        e.errorTips = "每隔10秒将再次尝试重连 WebSocket", e.ws.Timer = setInterval(e.connect_socket, 1e4));
                    },
                    ws_send: function(e) {
                        var t = this;
                        e = e || {
                            c: "Message",
                            a: "ping"
                        }, t.ws.SocketTask && t.ws.socketOpen ? r.sendSocketMessage({
                            data: JSON.stringify(e)
                        }) : (console.log("消息发送出错", e, t.ws.SocketTask, t.ws.socketOpen), t.ws.ErrorMsg.push(e));
                    },
                    send_message: function(e, t) {
                        var s = this;
                        if ("" != e) if (s.ws.SocketTask && s.ws.socketOpen) if (s.sessionId) {
                            if (0 == t) {
                                var o = (e = s.parseUrl(e)).match(/\[(.+?)\]/g);
                                if (o) for (var a in o) {
                                    var n = s.find_emoji(o[a]);
                                    e = e.replace(n.title, s.build_chat_img(n.src, "", "emoji"));
                                }
                            }
                            var i = {
                                c: "Message",
                                a: "sendMessage",
                                data: {
                                    message: e,
                                    message_type: t,
                                    session_id: s.sessionId,
                                    modulename: "index"
                                }
                            };
                            s.ws_send(i);
                            i = s.messageList[s.messageList.length - 1].data, i = {
                                id: i[i.length - 1].id + 1,
                                sender: "me",
                                message: e,
                                message_type: t
                            }, t = s.messageList.length - 1;
                            s.messageList[t] && "刚刚" == s.messageList[t].datetime ? s.messageList[t].data = s.messageList[t].data.concat(s.format_message([ i ])) : s.messageList = s.messageList.concat({
                                datetime: "刚刚",
                                data: s.format_message([ i ])
                            }), s.kefuMessage = "", s.kefu_message_change(), s.scroll_into_footer(300);
                        } else r.showToast({
                            title: "请选择一个会话~",
                            icon: "none"
                        }); else r.showToast({
                            title: "网络链接异常，请稍后重试~",
                            icon: "none"
                        }); else r.showToast({
                            title: "请输入消息内容",
                            icon: "none"
                        });
                    },
                    find_emoji: function(e) {
                        for (var t in this.expressionData) if (this.expressionData[t].title == e) return this.expressionData[t];
                        return !1;
                    },
                    build_chat_img: function(e, t) {
                        var s = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : "emoji";
                        return i.default.https_switch, "emoji" == s ? '<img class="emoji" src="' + e + '" />' : '<img class="' + s + '" src="' + e + '" />';
                    },
                    leave_message: function(e) {
                        "c-name" == e.currentTarget.id ? this.leaveMessage.name = e.detail.value : "c-contact" == e.currentTarget.id ? this.leaveMessage.contact = e.detail.value : "c-message" == e.currentTarget.id && (this.leaveMessage.message = e.detail.value);
                    },
                    post_leave_message: function() {
                        if (!this.leaveMessage.contact) return r.showToast({
                            title: "联系方式不能为空哦~",
                            icon: "none"
                        }), !1;
                        var e = {
                            c: "Message",
                            a: "leaveMessage",
                            data: this.leaveMessage
                        };
                        this.ws_send(e);
                    },
                    domsg: function(e) {
                        var t = this;
                        if ("initialize" == e.msgtype) {
                            e.data.new_msg && t.new_message_prompt();
                            var s = {
                                c: "Message",
                                a: "userInitialize",
                                data: {
                                    fixed_csr: t.fixedCsr
                                }
                            };
                            t.ws_send(s);
                        } else if ("user_initialize" == e.msgtype) 1 == e.code ? (e.data.session.user_tourists && (t.send_message = function() {
                            r.showToast({
                                title: "为保护您的隐私请,请登录后发送消息~",
                                icon: "none"
                            });
                        }), t.csr = e.data.session.csr, t.sessionId = e.data.session.id, t.showLeaveMessage = !1, 
                        r.setNavigationBarTitle({
                            title: "客服 " + e.data.session.nickname + " 为您服务"
                        })) : 302 == e.code && (t.csr ? r.showToast({
                            title: "当前客服暂时离开,您可以直接发送离线消息~",
                            icon: "none"
                        }) : (t.csr = "none", t.showLeaveMessage = !0, r.setNavigationBarTitle({
                            title: "当前无客服在线哦~"
                        }))); else if ("show_msg" == e.msgtype) r.showToast({
                            title: e.msg,
                            icon: "none"
                        }); else if ("leave_message" == e.msgtype) r.showToast({
                            title: e.msg,
                            icon: "none"
                        }), this.leaveMessage = {
                            name: "",
                            contact: "",
                            message: ""
                        }; else if ("clear" == e.msgtype) {
                            e.msg && r.showToast({
                                title: e.msg,
                                icon: "none"
                            });
                            t.ws_send({
                                c: "Message",
                                a: "clear"
                            }), t.retry_webSocket = function() {
                                clearInterval(t.ws.Timer);
                            };
                        } else if ("offline" == e.msgtype) e.user_id == t.csr && (this.errorTips = "客服离线~"); else if ("online" == e.msgtype) "admin" == e.modulename && (e.user_id == t.csr ? this.errorTips = "" : "none" == t.csr && (s = {
                            c: "Message",
                            a: "userInitialize"
                        }, t.ws_send(s))); else if ("csr_change_status" == e.msgtype) t.csr == e.data.csr && (3 != e.data.csr_status ? t.errorTips = "客服" + t.get_csr_status(e.data.csr_status) + "~" : t.errorTips = ""); else if ("transfer_done" == e.msgtype) t.csr = e.data.csr, 
                        r.setNavigationBarTitle({
                            title: "客服 " + e.data.nickname + " 为您服务"
                        }); else if ("new_message" == e.msgtype) t.new_message_prompt(), e.data.session_id == t.sessionId && (s = t.messageList.length - 1, 
                        "刚刚" == t.messageList[s].datetime ? t.messageList[s].data = t.messageList[s].data.concat(t.format_message([ e.data ])) : t.messageList = t.messageList.concat({
                            datetime: "刚刚",
                            data: t.format_message([ e.data ])
                        }), s = {
                            c: "Message",
                            a: "readMessage",
                            data: {
                                record_id: e.data.record_id
                            }
                        }, t.ws_send(s), t.scroll_into_footer(800)); else if ("chat_record" == e.msgtype) {
                            for (var o in t.chatRecordPage = e.data.next_page, e.data.chat_record) e.data.chat_record[o].data = t.format_message(e.data.chat_record[o].data);
                            if (1 == e.data.page) t.messageList = e.data.chat_record, t.scroll_into_footer(800); else for (var a = e.data.chat_record.length - 1; 0 <= a; a--) e.data.chat_record[a].data.reverse(), 
                            t.messageList.unshift(e.data.chat_record[a]);
                        }
                    },
                    get_csr_status: function(e) {
                        switch (parseInt(e)) {
                          case 0:
                            e = "离线";
                            break;

                          case 1:
                            e = "繁忙";
                            break;

                          case 2:
                            e = "离开";
                            break;

                          case 3:
                            e = "在线";
                            break;

                          case 99:
                            e = "断链";
                            break;

                          default:
                            e = "未知";
                        }
                        return e;
                    },
                    build_url: function() {
                        var e = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "ws", t = 1 < arguments.length ? arguments[1] : void 0, s = this, o = i.default.https_switch ? "https://" : "http://";
                        switch (e) {
                          case "ws":
                            var a = "&token=" + (s.tokenList.kefu_token || ""), n = "&kefu_user=" + (s.tokenList.kefu_tourists_token || "");
                            return ((o = 1 == parseInt(s.config.wss_switch) ? "wss://" : "ws://") + i.default.baseURL + ":" + s.config.websocket_port + "/?modulename=index" + a + n).replace(/\|/g, "~");

                          case "initialize":
                            return o + i.default.baseURL + "/addons/kefu/index/initialize?modulename=index";

                          case "upload":
                            return o + i.default.baseURL + "/addons/kefu/index/upload?modulename=index";

                          case "message_prompt":
                            return s.config.__CDN__ ? s.config.__CDN__ + "/assets/addons/kefu/audio/message_prompt.wav" : o + i.default.baseURL + "/assets/addons/kefu/audio/message_prompt.wav";

                          case "res":
                            return s.config.__CDN__ ? s.config.__CDN__ + "/assets/addons/kefu" + t : o + i.default.baseURL + "/assets/addons/kefu" + t;
                        }
                    },
                    new_message_prompt: function() {
                        c ? (c.play(), setTimeout(function() {
                            c.stop();
                        }, 1e3)) : console.error("来信提示音播放失败！");
                    },
                    scroll_into_footer: function() {
                        var e = this;
                        setTimeout(function() {
                            e.scrollIntoFooter = "wrapper_footer";
                        }, 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : 0), e.scrollIntoFooter = "";
                    },
                    wrapper_scrolltoupper: function() {
                        var e;
                        this.sessionId && "done" != this.chatRecordPage && (e = {
                            c: "Message",
                            a: "chatRecord",
                            data: {
                                session_id: this.sessionId,
                                page: this.chatRecordPage
                            }
                        }, this.ws_send(e));
                    },
                    tap_scroll_view: function() {
                        this.switch_show_tool(!1);
                    },
                    show_tool: function() {
                        var e = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "smiley";
                        this.showTool == e ? this.switch_show_tool(!1) : this.switch_show_tool(e), this.showTool && this.scroll_into_footer();
                    },
                    textarea_focus: function(e) {
                        this.showTool = !1, this.writeBottom = e.detail.height || 0;
                    },
                    textarea_input: function(e) {
                        this.kefuMessage = e.detail.value, this.kefu_message_change();
                    },
                    kefu_message_change: function() {
                        var t = this;
                        this.showSendButton = "" != this.kefuMessage, r.createSelectorQuery().select(".write").fields({
                            size: !0
                        }, function(e) {
                            e.height != t.wrapperHeight && (t.wrapperHeight = e.height);
                        }).exec();
                    },
                    kefu_message_blur: function() {
                        this.kefuMessageFocus = !1, this.showTool || (this.writeBottom = 0);
                    },
                    select_expression: function(e) {
                        this.kefuMessage = this.kefuMessage + e, this.kefu_message_change();
                    },
                    format_message: function(e) {
                        for (var t in e) if (4 == e[t].message_type || 5 == e[t].message_type) {
                            var s, o = e[t].message.split("#"), a = {};
                            for (s in o) {
                                var n = o[s].split("=");
                                void 0 !== n[1] && (a[n[0]] = n[1]);
                            }
                            e[t].message = a;
                        }
                        return e;
                    }
                }
            };
            a.default = t;
        }).call(this, n("543d").default);
    },
    "716a": function(e, t, s) {},
    e619: function(e, t, o) {
        (function(e) {
            o("767a"), s(o("66fd"));
            var t = s(o("fdd5"));
            function s(e) {
                return e && e.__esModule ? e : {
                    default: e
                };
            }
            wx.__webpack_require_UNI_MP_PLUGIN__ = o, e(t.default);
        }).call(this, o("543d").createPage);
    },
    f82b: function(e, t, s) {
        var o = s("716a");
        s.n(o).a;
    },
    faed: function(e, t, s) {
        s.d(t, "b", function() {
            return o;
        }), s.d(t, "c", function() {
            return a;
        }), s.d(t, "a", function() {});
        var o = function() {
            var s = this, e = (s.$createElement, s._self._c, s.selectModel && 0 < s.selectModelData.length ? s.__map(s.selectModelData, function(e, t) {
                return {
                    $orig: s.__get_orig(e),
                    g0: t.toString()
                };
            }) : null);
            s.$mp.data = Object.assign({}, {
                $root: {
                    l0: e
                }
            });
        }, a = [];
    },
    fdd5: function(e, t, s) {
        s.r(t);
        var o, a = s("faed"), n = s("0454");
        for (o in n) "default" !== o && function(e) {
            s.d(t, e, function() {
                return n[e];
            });
        }(o);
        s("f82b");
        var i = s("f0c5"), a = Object(i.a)(n.default, a.b, a.c, !1, null, null, null, !1, a.a, void 0);
        t.default = a.exports;
    }
}, [ [ "e619", "common/runtime", "common/vendor" ] ] ]);